package util;

import net.sf.json.util.PropertyFilter;

/**
 * JSON 属性过滤器
 */
public class JsonPropFilter implements PropertyFilter {
	private String[] props;

	public JsonPropFilter() {}

	public JsonPropFilter(String[] props) {
		this.props = props;
	}

	public void setProps(String[] prop) {
		this.props = prop;
	}

	public boolean apply(Object source, String name, Object value) {
		if (value == null) {
			return true;
		}

		if (props != null && props.length > 0) {
			if (juge(props, name)) {
				return true;
			}
			else {
				return false;
			}
		}

		return false;
	}

	private boolean juge(String[] props, String name) {
		for (String prop : props) {
			if (prop.equals(name)) {
				return true;
			}
		}

		return false;
	}
}
